﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using Common;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Web.Helpers.Documents.Spreadsheets;
using Web.Helpers.Documents.Spreadsheets.Enums;
using Newtonsoft.Json;
using Web.Pages;

namespace Web.Helpers
{
    public class PlanillasHelper
    {
        private static readonly System.Drawing.Color grisClaro   = System.Drawing.Color.FromArgb(233, 231, 224);
        private static readonly System.Drawing.Color grisOscuro  = System.Drawing.Color.FromArgb(201, 196, 179);

        public static string GenerarPlanilla(string infoPlanilla, string infoPlanillaItems)
        {
            var fileName = String.Empty;
            try
            {
                var path = String.Empty;

                var planillaInfo = JsonConvert.DeserializeObject<PlanillaInfo>(infoPlanilla);

                switch ( planillaInfo.TipoPlanilla )
                {
                    case TiposPlanilla.Actores:
                        path = Common.WellKnownKeys.Directories.Files.PlanillasPagosActores;
                        break;
                    case TiposPlanilla.Staff:
                        path = Common.WellKnownKeys.Directories.Files.PlanillasPagosStaff;
                        break;
                    case TiposPlanilla.Credito:
                        path = Common.WellKnownKeys.Directories.Files.PlanillasCreditos;
                        break;
                }

                fileName = GenerarNombreArchivo(planillaInfo, path);

                var fileStream = new FileStream( fileName, FileMode.Create, FileAccess.Write);
                var memoryStream = CrearDocumentoPlanilla( infoPlanilla, infoPlanillaItems );
                    memoryStream.WriteTo( fileStream );
                    fileStream.Close();
                    memoryStream.Close();
            }
            catch (Exception ex)
            {
                BasePage.LogError(ex);
                throw;
            }
            return fileName;
        }

        public static string ObtenerDirectorioPlanilla(TiposPlanilla tipoPlanilla)
        {
            // TODO => make this config key a Constant
            var appHost = ConfigurationManager.AppSettings["appHost"];
            if ( String.IsNullOrEmpty(appHost) )
                appHost = Helpers.FileHelper.GetServerRoot();

            var directorioPlanilla = String.Empty;
            switch (tipoPlanilla)
            {
                case TiposPlanilla.Actores:
                    directorioPlanilla = Common.WellKnownKeys.Directories.Files.PlanillasPagosActores;
                    break;
                case TiposPlanilla.Staff:
                    directorioPlanilla = Common.WellKnownKeys.Directories.Files.PlanillasPagosStaff;
                    break;
                case TiposPlanilla.Credito:
                    directorioPlanilla = Common.WellKnownKeys.Directories.Files.PlanillasCreditos;
                    break;
            }

            return appHost + directorioPlanilla;
        }

        public static PlanillaDePagoInfo DeserializarPlanillaDePagoInfo(string infoPlanilla, string infoPlanillaItems)
        {
            var planillaDePagoInfo        = JsonConvert.DeserializeObject<PlanillaDePagoInfo>(infoPlanilla);
                planillaDePagoInfo.Items  = JsonConvert.DeserializeObject<List<PlanillaDePagoItemInfo>>(infoPlanillaItems);
            
            return planillaDePagoInfo;
        }
        public static PlanillaDeCreditosInfo DeserializarPlanillaDeCreditosInfo(string infoPlanilla, string infoPlanillaItems)
        {
            var planillaCreditosInfo        = JsonConvert.DeserializeObject<PlanillaDeCreditosInfo>(infoPlanilla);
                planillaCreditosInfo.Items  = JsonConvert.DeserializeObject<List<PlanillaDeCreditosItemInfo>>(infoPlanillaItems);
            
            return planillaCreditosInfo;
        }
        
        private static string GenerarNombreArchivo(PlanillaInfo planillaInfo, string path)
        {
            var filename = String.Format( "{0}.pdf", planillaInfo.Titulo );
            return FileHelper.GetSafeFilename(path, filename);
        }
        private static MemoryStream CrearDocumentoPlanilla(string infoPlanilla, string infoPlanillaItems)
        {
            var ms = new MemoryStream();
            try
            {
                var document = new Document(PageSize.A4, 20, 20, 20, 20);
                var pdfWriter = PdfWriter.GetInstance(document, ms);

                document.Open();

                var pdfHelper = new PdfHelper();

                var defaultCell = new PdfHelper.CellStyle
                {
                    Font =
                        new PdfHelper.CellStyle.CellFont()
                        {
                            Family = Font.FontFamily.HELVETICA,
                            Size = 6f,
                            Type = PdfHelper.CellStyle.CellFont.FontType.Normal
                        },
                    Border = new PdfHelper.CellStyle.BorderStyle() { Color = grisClaro, Widths = new PdfHelper.TopLeftRightBottom() { Bottom = 0.5f, Left = 0.5f, Top = 0.5f, Right = 0.5f }}
                };

                pdfHelper.SetDefaultCell( defaultCell );

                var planillaInfo = JsonConvert.DeserializeObject<PlanillaInfo>(infoPlanilla);

                if (planillaInfo.TipoPlanilla == TiposPlanilla.Actores ||
                    planillaInfo.TipoPlanilla == TiposPlanilla.Staff)
                {
                    var planillaPagoInfo = Helpers.PlanillasHelper.DeserializarPlanillaDePagoInfo(infoPlanilla, infoPlanillaItems);

                    var tblEncabezado = CrearTablaEncabezado(pdfHelper, planillaPagoInfo);
                    document.Add(tblEncabezado);

                    var tblEmpresa = CrearTablaEmpresa(pdfHelper, planillaPagoInfo);
                    document.Add(tblEmpresa);

                    var tblPrograma = CrearTablaPrograma(pdfHelper, planillaPagoInfo);
                    document.Add(tblPrograma);

                    var tblItems = CrearTablaItems(pdfHelper, planillaPagoInfo);
                    document.Add(tblItems);

                    var tblComentarios = CrearTablaComentarios(pdfHelper, planillaPagoInfo);
                    document.Add(tblComentarios);

                    var tblTotales = CrearTablaTotales(pdfHelper, planillaPagoInfo);
                    document.Add(tblTotales);

                    var tblObservaciones = CrearTablaObservaciones(pdfHelper, planillaPagoInfo);
                    document.Add(tblObservaciones);   
                }

                if (planillaInfo.TipoPlanilla == TiposPlanilla.Credito)
                {
                    var planillaDeCreditosInfo = Helpers.PlanillasHelper.DeserializarPlanillaDeCreditosInfo(infoPlanilla, infoPlanillaItems);

                    var tblEncabezado = CrearTablaEncabezado(pdfHelper, planillaDeCreditosInfo);
                    document.Add(tblEncabezado);

                    var tblItems = CrearTablaItems(pdfHelper, planillaDeCreditosInfo);
                    document.Add(tblItems);
                }

                pdfWriter.CloseStream = false;
            
                document.Close();
            
                ms.Position = 0;
            }
            catch (Exception)
            {
                throw;
            }
            //return document;
            return ms;
        }
        
        #region Tablas
        private static PdfPTable CrearTablaEncabezado(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblEncabezado = null;
            try
            {
                var widths = new float[] { 350f, 200f };
                tblEncabezado = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };
                tblEncabezado.SetWidths( widths );

                var encabezadoIzq  = new PdfHelper.CellStyle { Span = {Rows = 3}, Padding = {Top = 5f, Left = 5f, Right = 5f, Bottom = 5f} };
                var encabezadoDer1 = new PdfHelper.CellStyle {Font = {Size = 8f}};
                var encabezadoDer2 = new PdfHelper.CellStyle {Font = {Size = 6f}};
                var encabezadoDer3 = new PdfHelper.CellStyle { Font = {Size = 12f, Type = PdfHelper.CellStyle.CellFont.FontType.Bold} };

                //var image = planilla.IdMedioPago == WellKnownKeys.Entities.MediosPago.ACTORES.Id ? Resources.AsociacionArgentinaActores : null;
                System.Drawing.Bitmap image = null;
                switch (planillaDePagoInfo.IdMedioPago)
                {
                    case WellKnownKeys.Entities.MediosPago.ACTORES.Id:
                        image = Resources.AsociacionArgentinaActores;
                        break;
                    case WellKnownKeys.Entities.MediosPago.EFECTIVO.Id:
                    case WellKnownKeys.Entities.MediosPago.TRANSFERENCIA.Id:
                        //image = Resources.Empty;
                        image = Resources.CajaDeRuidos;
                        break;
                }

                pdfHelper.InsertImage( tblEncabezado, Common.WellKnownKeys.Directories.Images.Root, image, 150f, 80f, encabezadoIzq );
                pdfHelper.AddCell( tblEncabezado, "PLANILLA DE REMUNERACIONES", encabezadoDer1 );
                pdfHelper.AddCell( tblEncabezado, "Para ser entregada en la Asociación Argentina de Actores", encabezadoDer2 );
                pdfHelper.AddCell( tblEncabezado, "RAMA: TELEVISION", encabezadoDer3 );
            }
            catch (Exception)
            {
                throw;
            }
            return tblEncabezado;
        }
        private static PdfPTable CrearTablaEncabezado(PdfHelper pdfHelper, PlanillaDeCreditosInfo planillaDeCreditosInfo)
        {
            var widths = new float[] { 250f, 300f }; //total: 550f
            var tblEncabezado = new PdfPTable(widths.Length);
            try
            {
                tblEncabezado.TotalWidth    = widths.Sum(width => width);
                tblEncabezado.LockedWidth   = true;
                tblEncabezado.SpacingBefore = 5f;
                tblEncabezado.SpacingAfter  = 5f;
                tblEncabezado.SetWidths(widths);

                var encabezado_izq = new PdfHelper.CellStyle
                {
                    Span = {Rows = 3},
                    Padding = {Top = 5f, Left = 5f, Right = 5f, Bottom = 5f}
                };

                var encabezado_der_1 = new PdfHelper.CellStyle {Font = {Size = 8f}};
                var encabezado_der_2 = new PdfHelper.CellStyle {Font = {Size = 12f}};
                var encabezado_der_3 = new PdfHelper.CellStyle
                {
                    Font = {Size = 12f, Type = PdfHelper.CellStyle.CellFont.FontType.Bold}
                };

                pdfHelper.InsertImage( tblEncabezado, Common.WellKnownKeys.Directories.Images.Root, Resources.CajaDeRuidos, 150f, 80f, encabezado_izq );
                pdfHelper.AddCell(tblEncabezado, "PLANILLA DE CRÉDITOS DE SERIE:", encabezado_der_1);
                pdfHelper.AddCell(tblEncabezado, planillaDeCreditosInfo.Titulo.ToUpper(), encabezado_der_2);
                pdfHelper.AddCell(tblEncabezado, String.Empty, encabezado_der_3);
            }
            catch (Exception)
            {
                throw;
            }
            return tblEncabezado;
        }
        private static PdfPTable CrearTablaEmpresa(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblEmpresa = null;
            try
            {
                var widths = new float[] { 60f, 110f, 130f, 110f, 60f, 80f };
                tblEmpresa = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };
                tblEmpresa.SetWidths( widths );

                pdfHelper.AddCell( tblEmpresa, "Razón Social", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.RazonSocial );

                pdfHelper.AddCell( tblEmpresa, "Apellido y Nombre del Responsable", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.Responsable );

                pdfHelper.AddCell( tblEmpresa, "Nro. Cuit", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.NroCuit );

                pdfHelper.AddCell( tblEmpresa, "Domicilio Legal", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.DomicilioLegal );

                pdfHelper.AddCell( tblEmpresa, "Apellido y Nombre del Contacto", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.Contacto );

                pdfHelper.AddCell( tblEmpresa, "Ingresos Brutos", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.IngresosBrutos );

                pdfHelper.AddCell( tblEmpresa, "Domicilio Real", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.DomicilioReal );

                pdfHelper.AddCell( tblEmpresa, "Teléfono Fijo del Contacto", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.ContactoTelefono );

                pdfHelper.AddCells( tblEmpresa, new string[] { "", "" } );

                pdfHelper.AddCell( tblEmpresa, "Teléfono / Fax", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.Telefono );

                pdfHelper.AddCell( tblEmpresa, "Teléfono Móvil del Contacto", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.ContactoCelular );

                pdfHelper.AddCells( tblEmpresa, new string[] { "", "" } );

                pdfHelper.AddCell( tblEmpresa, "Email", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.Email );

                pdfHelper.AddCell( tblEmpresa, "Email del Contacto", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblEmpresa, planillaDePagoInfo.ContactoEmail );

                pdfHelper.AddCells( tblEmpresa, new string[] { "", "" } );
            }
            catch (Exception)
            {
                throw;
            }
            return tblEmpresa;
        }
        private static PdfPTable CrearTablaPrograma(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblPrograma = null;
            try
            {
                var widths = new float[] { 35f, 120f, 35f, 120f, 50f, 70f, 50f, 70f };
                tblPrograma = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };
                tblPrograma.SetWidths( widths );

                var tblPrograma_Programa = new PdfHelper.CellStyle
                {
                    Span = {Cols = 4},
                    Colors = {Back = grisClaro},
                    Border = {Color = grisOscuro}
                };
                pdfHelper.AddCell( tblPrograma, "PROGRAMA", tblPrograma_Programa );

                var tblPrograma_Periodo = new PdfHelper.CellStyle
                {
                    Span = {Cols = 4},
                    Colors = {Back = grisClaro},
                    Border = {Color = grisOscuro}
                };
                pdfHelper.AddCell( tblPrograma, "PERÍODO", tblPrograma_Periodo );

                pdfHelper.AddCell( tblPrograma, "Título", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblPrograma, planillaDePagoInfo.Titulo );
                pdfHelper.AddCell( tblPrograma, "Autor", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblPrograma, planillaDePagoInfo.Autor );
                pdfHelper.AddCell( tblPrograma, "Desde", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblPrograma, planillaDePagoInfo.PeriodoDesde.ToShortDateString() );
                pdfHelper.AddCell( tblPrograma, "Hasta", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblPrograma, planillaDePagoInfo.PeriodoHasta.ToShortDateString() );
            }
            catch (Exception)
            {
                throw;
            }
            return tblPrograma;
        }
        private static PdfPTable CrearTablaItems(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblItems = null;
            try
            {
                var widths = new float[]{};
                var cols = new string[] {};

                if (planillaDePagoInfo.TipoPlanilla == TiposPlanilla.Actores)
                {
                    widths = new float[] { 10f, 40f, 40f, 70f, 40f, 30f, 35f, 35f, 35f, 40f, 35f, 35f, 35f, 35f, 35f };
                    cols = new string[] { "", "Tipo Doc.", "Nro. Doc.", "Nombre Artístico", "Fecha Grabación", "Capítulo", "Contrato", "Bolo", "Exteriores", "Excedentes", "Repetición", "Otros", "Remun. Total Bruta", "Viáticos", "Vales" };
                }
                if (planillaDePagoInfo.TipoPlanilla == TiposPlanilla.Staff)
                {
                    widths = new float[] { 10f, 50f, 60f, 150f, 60f, 50f, 50f, 120f };
                    cols = new string[] { "", "Tipo Doc.", "Nro. Doc.", "Nombre Artístico", "Fecha Grabación", "Capítulo", "Contrato", "Categoría" };
                }

                tblItems = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };
                tblItems.SetWidths( widths );

                var tblItemHeader = new PdfHelper.CellStyle
                {
                    Colors = {Back = grisClaro},
                    Border = {Color = grisOscuro}
                };

                pdfHelper.AddCells( tblItems, cols, tblItemHeader ); 

                var i = 1;
                foreach(var item in planillaDePagoInfo.Items)
                {
                    pdfHelper.AddCell( tblItems, i.ToString() );
                    pdfHelper.AddCell( tblItems, item.TipoDocumento );
                    pdfHelper.AddCell( tblItems, item.NroDocumento );
                    pdfHelper.AddCell( tblItems, item.Proveedor );
                    pdfHelper.AddCell( tblItems, item.FechaGrabacion.ToShortDateString() );
                    pdfHelper.AddCell( tblItems, item.Capitulo.ToString() );
                    pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Contrato) );

                    if (planillaDePagoInfo.TipoPlanilla == TiposPlanilla.Actores)
                    {
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Bolo) );
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Exteriores) );
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Exedentes) );
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Repeticion) );
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Otros) );
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.RemuneracionTotalBruta) );
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Viaticos));
                        pdfHelper.AddCell( tblItems, Formatter.ToCurrency(item.Vales) );
                    }

                    if (planillaDePagoInfo.TipoPlanilla == TiposPlanilla.Staff)
                    {
                        pdfHelper.AddCell(tblItems, item.ProveedorTipo);
                    }

                    i++;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return tblItems;
        }
        private static PdfPTable CrearTablaItems(PdfHelper pdfHelper, PlanillaDeCreditosInfo planillaDeCreditosInfo)
        {
            var widths = new float[] { 15f, 80f, 30f, 80f, 80f, 45f, 80f, 60f, 90f };

            PdfPTable tblItems = null;
            try
            {
                tblItems = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };
                tblItems.SetWidths( widths );
 
                var tblItem_Header = new PdfHelper.CellStyle
                {
                    Colors = {Back = grisClaro},
                    Border = {Color = grisOscuro}
                };

                pdfHelper.AddCells( tblItems, new string[] { "", "Proyecto", "Nro. Ep.", "Guion", "Actor", "Nro. Matrícula", "Personaje", "Teléfono", "Email" }, tblItem_Header); 

                var i = 1;
                foreach(var item in planillaDeCreditosInfo.Items)
                {
                    pdfHelper.AddCell( tblItems, i.ToString() );
                    pdfHelper.AddCell( tblItems, item.Proyecto );
                    pdfHelper.AddCell( tblItems, item.NroEpisodio.ToString() );
                    pdfHelper.AddCell( tblItems, item.Guion );
                    pdfHelper.AddCell( tblItems, item.Actor );
                    pdfHelper.AddCell( tblItems, item.NroMatricula);
                    pdfHelper.AddCell( tblItems, item.Personaje);
                    pdfHelper.AddCell( tblItems, item.Telefono );
                    pdfHelper.AddCell( tblItems, item.Email );
                    i++;
                }
                
            }
            catch (Exception)
            {
                throw;
            }
            return tblItems;
        }
        private static PdfPTable CrearTablaComentarios(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblComentarios = null;
            try
            {
                var widths = new float[] { 550f };
                tblComentarios = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };

                pdfHelper.AddCell( tblComentarios, "Detalle \"Otros\":"  );
                pdfHelper.AddCell( tblComentarios, planillaDePagoInfo.DetallesOtros );
            }
            catch (Exception)
            {
                throw;
            }
            return tblComentarios;
        }
        private static PdfPTable CrearTablaTotales(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblTotales = null;
            try
            {
                var widths = new float[] { 70f, 90f, 90f, 90f, 130f, 80f };
                tblTotales = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };
                tblTotales.SetWidths( widths );

                pdfHelper.AddCell( tblTotales, "" );
                pdfHelper.AddCell( tblTotales, "RECIBIÓ" );
                pdfHelper.AddCell( tblTotales, "AUTORIZÓ" );
                pdfHelper.AddCell( tblTotales, "ASENTÓ" );
                pdfHelper.AddCell( tblTotales, "TOTAL GENERAL REMUNERACIONES");
                pdfHelper.AddCell( tblTotales, Formatter.ToCurrency(planillaDePagoInfo.TotalGeneralRemuneraciones) );

                var rowspan2 = new PdfHelper.CellStyle {Span = {Rows = 2}};

                pdfHelper.AddCell( tblTotales, "ACLARACIÓN", rowspan2 );
                pdfHelper.AddCell( tblTotales, "X", rowspan2 );
                pdfHelper.AddCell( tblTotales, "X", rowspan2 );
                pdfHelper.AddCell( tblTotales, "X", rowspan2 );

                if (planillaDePagoInfo.TipoPlanilla == TiposPlanilla.Actores)
                {
                    pdfHelper.AddCell( tblTotales, "TOTAL CONTRIBUCION OSA 6 %" );
                    pdfHelper.AddCell( tblTotales,  Formatter.ToCurrency(planillaDePagoInfo.TotalContribucionOsa) );
                }
                pdfHelper.AddCell( tblTotales, "TOTAL A DEPOSITAR", PdfHelper.CellStyle.CellFont.FontType.Bold );
                pdfHelper.AddCell( tblTotales,  Formatter.ToCurrency(planillaDePagoInfo.TotalDeposito) );

                pdfHelper.AddCell( tblTotales, "FIRMA", rowspan2 );
                pdfHelper.AddCell( tblTotales, "X", rowspan2 );
                pdfHelper.AddCell( tblTotales, "X", rowspan2 );
                pdfHelper.AddCell( tblTotales, "X", rowspan2 );
                pdfHelper.AddCell( tblTotales, "NETO" );
                pdfHelper.AddCell( tblTotales,  Formatter.ToCurrency(planillaDePagoInfo.TotalNeto) );

                if (planillaDePagoInfo.TipoPlanilla == TiposPlanilla.Actores)
                {
                    pdfHelper.AddCell( tblTotales, "3% SINDICAL" );
                    pdfHelper.AddCell( tblTotales,  Formatter.ToCurrency(planillaDePagoInfo.TotalContribucionSindicato) );
                }

            }
            catch (Exception)
            {
                throw;
            }
            return tblTotales;
        }
        private static PdfPTable CrearTablaObservaciones(PdfHelper pdfHelper, PlanillaDePagoInfo planillaDePagoInfo)
        {
            PdfPTable tblComentarios = null;
            try
            {
                var widths = new float[] { 550f };
                tblComentarios = new PdfPTable( widths.Count() )
                {
                    TotalWidth = widths.Sum(),
                    LockedWidth = true,
                    SpacingBefore = 5f,
                    SpacingAfter = 5f
                };

                pdfHelper.AddCell( tblComentarios, "Observaciones:"  );
                pdfHelper.AddCell( tblComentarios, planillaDePagoInfo.Observaciones );
            }
            catch (Exception)
            {
                throw;
            }
            return tblComentarios;
        }
        #endregion
    }
}